package baiqitun.netfiles.util;

import baiqitun.netfiles.model.NavItem;
import org.springframework.web.servlet.ModelAndView;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

/**
 * 用于模板引擎渲染的网页公用的配置
 * @author kedaji
 */
public class ThymeleafUtil {
    /**
     * 每个Thymeleaf模板公用的配置
     */
    public static ModelAndView createDefaultModelAndView(){
        ModelAndView mav = new ModelAndView();

        mav.addObject("lang", "zh_CN");
        mav.addObject("author", "kedaji");
        mav.addObject("logo", "/img/logo.png");
        mav.addObject("description", "NetFiles远程文件浏览器是一款小巧的远程文件浏览器，将它部署到服务器后，客户端可拥有远程浏览服务器文件的能力。");

        Map<String, NavItem> navs = new HashMap<>();

        NavItem homeNav = new NavItem();
        homeNav.setLink("/index");
        homeNav.setName("首页");
        navs.put("home", homeNav);

        NavItem aboutNav = new NavItem();
        aboutNav.setLink("/about");
        aboutNav.setName("关于");
        navs.put("about", aboutNav);

        NavItem browse = new NavItem();
        browse.setLink("/browse");
        browse.setName("浏览");
        navs.put("browse", browse);

        List<Map<String, String>> features = new LinkedList<>();

        Map<String, String> feature1 = new HashMap<>();
        feature1.put("title", "跨平台");
        feature1.put("content", "基于Java，可支持Linux、Windows、Mac OS等系统。\n" +
                "前端使用BootStrap框架实现,同时支持PC端和移动端访问。");
        features.add(feature1);

        Map<String, String> feature2 = new HashMap<>();
        feature2.put("title", "安全");
        feature2.put("content", "应用主键路径映射，不暴露真实路径给客户端，减少信息泄露风险");
        features.add(feature2);

        Map<String, String> feature3 = new HashMap<>();
        feature3.put("title", "快速部署");
        feature3.put("content", "项目本体不超过10M  \n" +
                "只需要提前安装Java运行时环境，启动Redis后，然后就可以使用\n" +
                "<code>java -jar netfiles.jar</code>\n" +
                "的命令启动本项目。");
        features.add(feature3);

        mav.addObject("features", features);
        mav.addObject("navs", navs);
        mav.addObject("cssHrefList", cssHrefList());
        mav.addObject("scriptSrcList", scriptSrcList());

        return mav;
    }

    private static List<String> cssHrefList(){
        List<String> hrefList = new LinkedList<>();
        hrefList.add("/css/linearicons.css");
        hrefList.add("/css/font-awesome.min.css");
        hrefList.add("/css/bootstrap.css");
        hrefList.add("/css/magnific-popup.css");
        hrefList.add("/css/owl.carousel.css");
        hrefList.add("/css/nice-select.css");
        hrefList.add("/css/hexagons.min.css");
        hrefList.add("/plugin/viewer/viewer.css");
        hrefList.add("/css/main.css");


        return hrefList;
    }

    private static List<String> scriptSrcList(){
        List<String> srcList = new LinkedList<>();
        srcList.add("/js/vendor/jquery-2.2.4.min.js");
        srcList.add("/js/vendor/bootstrap.min.js");
        srcList.add("/js/jquery.ajaxchimp.min.js");
        srcList.add("/js/jquery.magnific-popup.min.js");
        srcList.add("/js/parallax.min.js");
        srcList.add("/js/owl.carousel.min.js");
        srcList.add("/js/jquery.sticky.js");
        srcList.add("/js/hexagons.min.js");
        srcList.add("/js/jquery.counterup.min.js");
        srcList.add("/js/waypoints.min.js");
        srcList.add("/js/jquery.nice-select.min.js");
        srcList.add("/plugin/viewer/viewer.js");
        srcList.add("/plugin/videojs/video.js");
        srcList.add("/js/main.js");

        return srcList;
    }
}
